package collectionexercise;



import java.util.ArrayList;
import java.util.Collection;



public class CollectionDemo {
    public static void main(String[] args) {
        Collection c=new ArrayList();
        c.add("one");
        c.add("two");
        c.add("three");
        c.add("four");
        c.add("five");
        System.out.println(c);//[one,two,three,four,five]

        System.out.println("size:"+c.size());//集合元素的个数
        System.out.println("是否为空集："+c.isEmpty());

        c.clear();
        System.out.println(c);
        System.out.println("size:"+c.size());
        System.out.println("是否为空集:"+c.isEmpty());

        Collection c1=new ArrayList();
        c1.add(new Point(1,2));
        c1.add(new Point(2,3) );
        c1.add(new Point(3,4));
        c1.add(new Point(5,6));
        System.out.println(c1);
        //比较当前集合是否与给定元素存在equals()比较为true的情况
        Point p=new Point(1,2);
        System.out.println(c1.contains(p));//true

        Point p1=new Point(3,5);
        System.out.println(c1.contains(p1));//false
//remove(),返回结果为bollean一般不接收
        c1.remove(p);
        System.out.println(c1);

        c1.remove(p1);
        System.out.println(c1);

        //集合存放的是元素的引用,数组
        Collection cc=new ArrayList();
        Point pp=new Point(4,8);
        cc.add(pp);
        System.out.println("cc:"+cc);
        System.out.println("pp:"+pp);
        pp.setX(100);
        System.out.println("cc:"+cc);
        System.out.println("pp:"+pp);



    }
}
